package com.yunduo.common.RetunData;

import com.yunduo.common.RetunData.statuscode.ResultStatus;

import java.util.HashMap;
import java.util.Map;

/**
 * 公共返回类
 */
public class CommonReturn {
    //是否成功
    private Boolean success;

    //返回码
    private Integer code;

    //返回消息
    private String message;

    //返回数据
    private Map<String,Object> data = new HashMap<>();

    //构造方法私有
    private CommonReturn(){
    }

    //操作失败
    public static CommonReturn ERROR(ResultStatus status){
        CommonReturn r = new CommonReturn();
        r.success = false;
        r.code = status.getCode();
        r.message = status.getInfo();
        return r;
    }

    //操作成功
    public static CommonReturn SUCCESS(ResultStatus status,Map<String,Object> data){
        CommonReturn r = ERROR(status);
        r.success=true;
        r.data = data;
        return r;
    }

    //成功 无数据
    public static CommonReturn SUCCESS(ResultStatus status){
        CommonReturn r = ERROR(status);
        r.success=true;
        return r;
    }

    public CommonReturn  setSuccess(Boolean success) {
        this.success = success;
        return this;
    }

    public CommonReturn setCode(Integer code) {
        this.code = code;
        return this;
    }

    public CommonReturn setMessage(String message) {
        this.message = message;
        return this;
    }

    public CommonReturn setData(String key,Object value) {
        this.data.put(key,value);
        return this;
    }

    public Boolean getSuccess() {
        return success;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public Map<String, Object> getData() {
        return data;
    }
}
